package com.example.mylibrary.testActivity.util;
import android.bluetooth.BluetoothAdapter;
public class bluetoothUtil {
    private static bluetoothUtil instance;
    private BluetoothAdapter mBluetooth;
    //获取Bluetooth适配器
    private bluetoothUtil(){mBluetooth = BluetoothAdapter.getDefaultAdapter(); }
    public static bluetoothUtil getInstance(){
        if(instance == null) {  synchronized (bluetoothUtil.class) { if (instance == null) instance = new bluetoothUtil(); }}
        return instance;
    }
    /**
     *  检测蓝牙的开关状态
     * @return  true 是蓝牙已经打开  false  蓝牙处于关闭状态
     */
    public boolean getBluetooth(){ return mBluetooth.isEnabled(); }
    /**
     * 打开蓝牙
     * @return  true 是蓝牙已经打开  false  蓝牙未能打开
     */
    public void OpenBluetooth(){
        if (getBluetooth()) return ;
        else  mBluetooth.enable();
    }
    /**
     * 关闭蓝牙
     * @return  true 是蓝牙已经关闭  false 蓝牙未能关闭
     */
    public void CloseBluetooth(){
        if (!getBluetooth()) return ;
        else mBluetooth.disable();
    }
}
